package com.example.administrator.yunniuusedcar.holder;

import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.daimajia.slider.library.SliderLayout;
import com.daimajia.slider.library.SliderTypes.BaseSliderView;
import com.daimajia.slider.library.SliderTypes.TextSliderView;
import com.example.administrator.yunniuusedcar.MainActivity;
import com.example.administrator.yunniuusedcar.adapter.HomeCategoryAdapter;
import com.example.administrator.yunniuusedcar.model.mode_benn.ADbeen;
import com.example.administrator.yunniuusedcar.model.mode_benn.Home;
import com.example.administrator.common.base.Global;
import com.example.administrator.common.ui.BaseAdapterRV;
import com.example.administrator.common.ui.BaseHolderRV;
import com.example.administrator.common.utils.util;
import com.example.administrator.yunniuusedcar.R;
import com.example.administrator.yunniuusedcar.model.mode_benn.HomeMenuBean;
import com.example.administrator.yunniuusedcar.ui.HomePagerActivity;
import com.squareup.picasso.Picasso;

import java.util.List;

/** 头部
 * Created by USER2015 on 2017/12/4.
 */

public class Home01HeaderHolder extends BaseHolderRV<ADbeen> {

    private SliderLayout sliderLayout;
    private RecyclerView recyclerView02;
    private HomeCategoryAdapter homeCategoryAdapter;

    public Home01HeaderHolder(Context context, ViewGroup parent, BaseAdapterRV<ADbeen> adapter) {
        super(context, parent, adapter, R.layout.item_home_header);
    }

    // 查找列表项中的子控件
    @Override
    public void onFindViews(View itemView) {
        // 1. 轮播图
        sliderLayout = (SliderLayout) itemView.findViewById(R.id.slider_layout);
        /*// 2. 促销类型RecyclerView  随机汽车
        recyclerView02 = (RecyclerView) itemView.findViewById(R.id.recycler_view);
        recyclerView02.setLayoutManager(new GridLayoutManager(
                context, 2, RecyclerView.HORIZONTAL, false));
        homeCategoryAdapter = new HomeCategoryAdapter(context, null);
        recyclerView02.setAdapter(homeCategoryAdapter);*/

    }

    // 刷新列表项中子控件的显示
    @Override
    protected void onRefreshView(ADbeen bean1, int position) {
        bean1 = (ADbeen)bean;
        // 1.首页 轮播图
        initLooperView(bean.data);      // 数量！！！！

       /* // 2. 促销车型平台RecyclerView
        homeCategoryAdapter.setDatas(bean.Dataruncars());   //getPromotionTypes*/

    }


    // 显示轮播图
    private void initLooperView(List<ADbeen.Data> datas) {
        sliderLayout.removeAllSliders();  // 清除之前的子界面 (刷新界面时调用)

        for (final  ADbeen.Data bead: datas){    //bead
            TextSliderView item = new TextSliderView(Global.mContext);
          //  Picasso.with(context).load(bead.logo).into(item.);
            item.image(bead.logo);  // tupian
            //点击图片跳转的监听
            item.setOnSliderClickListener(new BaseSliderView.OnSliderClickListener() {
                @Override
                public void onSliderClick(BaseSliderView slider) {
                    // 点击事件

                }
            });
            sliderLayout.addSlider(item);
        }

//        for (final Home.DatagoodsListsBeen bean : datas) {
//            // TextSliderView: 代表一个子界面
//            TextSliderView item = new TextSliderView(Global.mContext);
//
//
//
//            // 点击事件监听
//            item.setOnSliderClickListener(new BaseSliderView.OnSliderClickListener() {
//                @Override
//                public void onSliderClick(BaseSliderView slider) {
//                    Global.showToast(bean.getTitle());
//                }
//            });

      //      sliderLayout.addSlider(item);
        }

    @Override
    protected void onItemClick(View itemView, int position, ADbeen bean) {
        super.onItemClick(itemView, position, bean);

        Intent intent = new Intent(MainActivity.mactivity, HomePagerActivity.class);

//        intent.putExtra("springId",bean.data);   //advert_id
        intent.putExtra("slip", bean.data.get(position).logo);
        MainActivity.mactivity.startActivity(intent);

    }
}


